package gui;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

import Game.Genre;
import Game.Position;
import Game.Settings;

public class GamePanel extends JPanel{
	private int MarginLeft = 10;
	private int MarginTop = 10;
	private boolean drawBattle = false;
	private Position[][] Battlefield = null;
		
	public GamePanel() {
		this.setSize(MarginLeft + Settings.WIDTH, MarginTop +  Settings.HEIGHT);
		this.setVisible(true);
	}
	
	protected void paintComponent(Graphics g){
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(new Color(128, 64, 0));
		g.fillRect(MarginLeft,MarginTop, Settings.WIDTH, Settings.HEIGHT);
		g.setColor(Color.BLACK);
//		g.drawLine((Settings.WIDTH+MarginLeft)/2, MarginTop, (Settings.WIDTH+MarginLeft)/2, Settings.HEIGHT+MarginTop);
//		g.drawLine(MarginLeft,(Settings.HEIGHT+MarginTop)/2, Settings.WIDTH+MarginLeft, (Settings.HEIGHT+MarginTop)/2);
		
		//rysowanie mrowek
		if(drawBattle){	
			
			for(int i = 0; i<Battlefield.length; i++ ){
				for(int j = 0; j<Battlefield[i].length; j++){
					if(!Battlefield[i][j].isBlank()){
						g.setColor(Battlefield[i][j].getAntColor());
						if(!Battlefield[i][j].isBlank() && Battlefield[i][j].getAnt().getGenre() == Genre.MALE){
							g.fillRect(MarginLeft + Battlefield[i][j].getX()*Settings.ANT_SIZE,							
								   MarginTop + Battlefield[j][j].getY()*Settings.ANT_SIZE, 
								   Settings.ANT_SIZE, 
								   Settings.ANT_SIZE);
						}
						else {
							g.fillOval(MarginLeft + Battlefield[i][j].getX()*Settings.ANT_SIZE,							
									   MarginTop + Battlefield[j][j].getY()*Settings.ANT_SIZE, 
									   Settings.ANT_SIZE, 
									   Settings.ANT_SIZE);
						}
						g.setColor(Color.BLACK);
					}
					
				}
			}
			drawBattle = false;
		}
//		for(int i = MarginTop; i<=Settings.HEIGHT+MarginTop; i+=Settings.ANT_SIZE){
//			g.drawLine(MarginLeft, i, Settings.WIDTH+MarginLeft, i);
//		}
//		
//		for(int i = MarginLeft; i<=Settings.WIDTH+MarginLeft; i+=Settings.ANT_SIZE){
//			g.drawLine(i, MarginTop, i, Settings.HEIGHT+MarginTop);
//		}
	}
	
	public void updateAnts(Position[][] battle){
		Battlefield = battle;
		drawBattle = true;
		this.repaint();
	}
	
}
